<?php
declare (strict_types=1);

namespace app\service;

use app\db\BigDb;

class BigService
{
    protected $bigDb;

    public function __construct(BigDb $bigDb)
    {
        $this->bigDb = $bigDb;
    }


    //合并接口
    public function bigshow($uniacid, $id, $themeid)
    {
        $arr = $this->bigDb->comDbfindtheme($uniacid, $id); //含有  7访客 12345
        $fanssum = 0;
        if (!is_null($arr['vdata'])) {
            $fanssum = $arr['vdata']['fanssum'];
        }

        $zhuncusarr = $this->zhuncus($uniacid, $themeid);
        $newarr = $this->newoldcus($uniacid, $themeid, '新');
        $oldarr = $this->newoldcus($uniacid, $themeid, '老');


        //6准客
        $zhuncus = $zhuncusarr['vdata']['num']; //是num
        $arr['vdata']['zhuncus'] = $zhuncus;
        //8新
        $new = $newarr['vdata']['num'];
        $arr['vdata']['newnum'] = $new;
        //9老
        $old = $oldarr['vdata']['num'];
        $arr['vdata']['oldnum'] = $old;

        //10已支付
        $payonarr = $this->payon($uniacid, $themeid);
        $payon = $payonarr['vdata']['num'];
        $arr['vdata']['payon'] = $payon;

        //11 计算未支付
        //首先判断访客是否大于0
        $payoff = 0;
        if ($fanssum > 0 &&  $fanssum >$payon ) {
            $payoff = $fanssum- $payon;
        }
        $arr['vdata']['payoff'] = $payoff;
        return $arr;
    }

    /**
     * 执行服务
     *
     * @return mixed
     */
    public function zhuncus($uniacid, $themeid)
    {
        return $this->bigDb->zhuncus($uniacid, $themeid);
    }


    //访客
    public function findone002($uniacid, $id)
    {
        return $this->bigDb->findone002($uniacid, $id);
    }

    //访客
    //todo 重构
    public function fanssum($uniacid, $id)
    {
        //return $this->bigDb->fanssum($uniacid,$id);
        return $this->bigDb->fanssum($uniacid, $id);
    }

    //处理未支付 payoff
    public function payoff($uniacid, $themeid, $id)
    {
        //return $this->bigDb->fanssum($uniacid,$id);
        $arr = $this->fanssum($uniacid, $id); //不一定要访问DB
        if (!is_null($arr['vdata'])) {
            //有访客
            $paramarr = $this->payon($uniacid, $themeid);
            $data = $paramarr['data'][0];
            $arr['numobj'] = $data; //已支付有10个
            $arr['已支付人数'] = $data['num'];
            $arr['访客数'] = $arr['vdata']['fanssum'];
            $arr['未支付人数'] = $arr['vdata']['fanssum'] - $data['num'];
            $arr['vdata']['payoff'] = $arr['vdata']['fanssum'] - $data['num'];
        }
        //
        return $arr;
    }


    public function findone003($uniacid, $id)
    {
        return $this->bigDb->fanssum($uniacid, $id);
    }


    //activitietitle
    public function activitietitle($uniacid, $id)
    {
        return $this->bigDb->activitietitle($uniacid, $id);
    }

    //ordersum
    public function ordersum($uniacid, $id)
    {
        return $this->bigDb->ordersum($uniacid, $id);
    }

    //countdown
    public function countdown($uniacid, $id)
    {
        return $this->bigDb->countdown($uniacid, $id);
    }

    //fullgourp 满团
    public function fullgourp($uniacid, $id)
    {
        return $this->bigDb->fullgourp($uniacid, $id);
    }

    //ui
    public function ui($uniacid, $id)
    {
        return $this->bigDb->ui($uniacid, $id);
    }

    public function ut($uniacid, $themeid)
    {
        return $this->bigDb->ut($uniacid, $themeid);
    }

    //payon
    public function payon($uniacid, $themeid)
    {
        return $this->bigDb->payon($uniacid, $themeid);
    }

    //newcus
    public function newoldcus($uniacid, $themeid, $newold)
    {
        return $this->bigDb->newoldcus($uniacid, $themeid, $newold);
    }

    //cusanking
    public function cusanking($uniacid, $themeid)
    {
        return $this->bigDb->cusanking($uniacid, $themeid);
    }

    public function worker($uniacid, $themeid)
    {
        return $this->bigDb->worker($uniacid, $themeid);
    }
    //fans
    public function fans($uniacid, $themeid)
    {
        return $this->bigDb->fans($uniacid, $themeid);
    }

    //15.员工业绩排行榜总人数
    public function workertop($uniacid, $themeid){

        return $this->bigDb->workertop($uniacid, $themeid);
    }

    //grouptop 16团队排行榜
    public function grouptop($uniacid, $themeid){

        return $this->bigDb->grouptop($uniacid, $themeid);
    }

    //redtop 17 红包排行
    public function redtop($uniacid, $themeid){
        return $this->bigDb->redtop($uniacid, $themeid);
    }

    //eventslist
    public function eventslist($uniacid, $themeid){
        return $this->bigDb->eventslist($uniacid, $themeid);
    }

}
